package config

import (
	"encoding/json"
	"socks5_proxy/src/util"
)

var (
	CONFIG_NAME = "socks5.json"
)

type Config struct {
	ServiceAddr string 	`json:"service_addr"`
	LogFile string 		`json:"log_file"`
	LogLevel string 	`json:"log_level"`
}

var c Config

func LoadConfig() error {
	if exist, _ := util.IsFileExists(CONFIG_NAME); exist != true {
		return util.ErrFileNotExisted
	}

	content, err := util.ReadContent(CONFIG_NAME)
	if err != nil {
		return util.ErrFileCanNotRead
	}

	err = json.Unmarshal([]byte(content), &c)
	if err != nil {
		return err
	}

	return nil
}

func GetConfig() *Config {
	return &c
}
